package com.vm.action.brand;

import org.apache.log4j.Logger;

import com.opensymphony.xwork2.Preparable;
import com.vm.action.ActionSuper;
import com.vm.common.Page;
import com.vm.dao.brand.BrandDAO;
import com.vm.entity.Brand;
import com.vm.log4j.CustomizeLog4j;

public class BrandAction extends ActionSuper implements Preparable {


	private static Logger log = CustomizeLog4j.getLogger(BrandAction.class);
	private Page<Brand> page;
	private Brand brand;
	private BrandDAO brandDao;
	private String pageLinkList;

	


	@Override
	public void prepare() throws Exception {
		// TODO Auto-generated method stub
		
	}
	
	
	public String list(){
		this.page = this.brandDao.page(this.PAGE_ROW_SIZE, super.getPageNumber());
		this.pageLinkList =super.getSplitPageLink("/brand/brandAction_list.do?", this.page);
		return SUCCESS;
	}
	
	public String add() throws Exception {
		return SUCCESS;
	}

	public String save() throws Exception {
		String[] msgArg = new String[] { "brandAction_list.do"};
		String msg = null;
		try {
			brandDao.save(brand);
			msg = super.getResourceMessage("insert_brand_success", msgArg);
		} catch (Exception e) {
			log.error("Brand save Brand error  ", e);
			msg = super.getResourceMessage("insert_brand_err", msgArg);
		}
		super.setShowMessage(msg);
		return super.SHOW_MESSAGE_RESULT;
	}

	public String edit(){
		brand = brandDao.findById(this.brand.getId());
		return SUCCESS;
	}

	public String update() throws Exception {
		String[] msgArg = new String[] { "brandAction_list.do"};
		String msg = null;
		try {
			brandDao.update(brand);
			msg = super.getResourceMessage("update_brand_success", msgArg);
		} catch (Exception e) {
			log.error("Brand save Brand error  ", e);
			msg = super.getResourceMessage("update_brand_err", msgArg);
		}
		super.setShowMessage(msg);
		return super.SHOW_MESSAGE_RESULT;

	}

	public String delete() {
		String[] msgArg = new String[] { "brandAction_list.do"};
		String msg = null;
		try {
			brandDao.deleteById(this.brand.getId());
			msg = super.getResourceMessage("delete_Brand_success", msgArg);
		} catch (Exception e) {
			log.error("BrandAction delete Brand error  ", e);
			msg = super.getResourceMessage("delete_Brand_err", msgArg);
		}
		super.setShowMessage(msg);
		return super.SHOW_MESSAGE_RESULT;
	}
   
	public Page<Brand> getPage() {
		return page;
	}


	public void setPage(Page<Brand> page) {
		this.page = page;
	}


	public Brand getBrand() {
		return brand;
	}


	public void setBrand(Brand brand) {
		this.brand = brand;
	}


	public BrandDAO getBrandDao() {
		return brandDao;
	}


	public void setBrandDao(BrandDAO brandDao) {
		this.brandDao = brandDao;
	}


	public String getPageLinkList() {
		return pageLinkList;
	}


	public void setPageLinkList(String pageLinkList) {
		this.pageLinkList = pageLinkList;
	}

	
	



}
